import org.apache.spark.SparkConf
import org.apache.spark.sql.{SaveMode, SparkSession}

object all{
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
      .setMaster("local[*]")
    //2. SparkSession对象
    val sparkSession = SparkSession
      .builder()
      .enableHiveSupport() //-开启hive的支持
      .config(sparkConf)
      .appName("mysql")
      .getOrCreate()
    val tb_produce = sparkSession.sql("select * from db_produce.line_num")
    tb_produce.write
      .format("jdbc")
      .option("url","jdbc:mysql://192.168.244.130:3306/producedb")
      .option("user","root")
      .option("password","root")
      .option("dbtable","line_num")
      .mode(SaveMode.Append)
      .save()
    sparkSession.stop()
    sparkSession.close()

  }

}